package org.xqyy.eval.service.impl;

import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.xqyy.eval.dao.DeptGroupMapper;
import org.xqyy.eval.dao.IDeptGroupDao;
import org.xqyy.eval.dao.TDeptGroupMapper;
import org.xqyy.eval.model.Dept;
import org.xqyy.eval.model.DeptGroup;
import org.xqyy.eval.model.TDeptGroup;
import org.xqyy.eval.service.IDeptGroupService;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by luoxiaoming on 16-12-24.
 */

@Component
@Transactional
public class DeptGroupService implements IDeptGroupService {

    @Resource
    private IDeptGroupDao deptGroupDao;
    @Resource
    private DeptGroupMapper deptGroupMapper;
    @Autowired
    private TDeptGroupMapper tDeptGroupMapper;
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public void add(Map<String, Object> params) {
        deptGroupDao.add(params);
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public void modify(Map<String, Object> params) {
        deptGroupDao.modify(params);
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public void delete(Map<String, Object> params) {
        deptGroupDao.delete(params);
    }

    @Override
    public Map<String, Object> loadOne(String groupCode) {
        Map<String, Object> params = new HashedMap();
        params.put("code", groupCode);
        return deptGroupDao.loadOne(params);
    }

    @Override
    public List<Map<String, Object>> load(Map<String, Object> params) {
        return deptGroupDao.load(params);
    }

    @Override
    public List<DeptGroup> selecAllDepGroup() {

        return   deptGroupMapper.selectAll();
    }

    /**
     * 新的增加科室分组
     *
     * @param deptGroup
     * @return
     */
    @Override
    public Boolean addTDeptGroup(TDeptGroup deptGroup) {
        deptGroup.setId(null);
        tDeptGroupMapper.insert(deptGroup);
        return true;
    }

    /**
     * 根据id查询科室分组
     *
     * @param deptGroup
     * @return
     */
    @Override
    public TDeptGroup findTDeptGroupById(TDeptGroup deptGroup) {
        return tDeptGroupMapper.selectByPrimaryKey(deptGroup.getId());
    }

    /**
     * 新的修改科室分组
     *
     * @param deptGroup
     * @return
     */
    @Override
    public Boolean updateTDeptGroup(TDeptGroup deptGroup) {
        tDeptGroupMapper.updateByPrimaryKey(deptGroup);
        return true;
    }

    /**
     * 新的查询所有科室分组
     *
     * @return
     */
    @Override
    public List<TDeptGroup> selectAllTDeptGroup() {
        return tDeptGroupMapper.selectAll();
    }

    /**
     * 新的删除科室分组
     *
     * @param deptGroup
     * @return
     */
    @Override
    public Boolean delTDeptGroup(TDeptGroup deptGroup) {
        tDeptGroupMapper.deleteByPrimaryKey(deptGroup.getId());
        return true;
    }


}
